package com.ts.api.module.app.market.controller;

import com.gitee.apanlh.annotation.viewresolver.RequestParamVo;
import com.gitee.apanlh.util.base.IteratorUtils;
import com.gitee.apanlh.util.reflection.CopyUtils;
import com.gitee.apanlh.util.valid.ValidParam;
import com.gitee.apanlh.web.model.vo.RequestVO;
import com.gitee.apanlh.web.model.vo.ResultVO;
import com.ts.api.module.app.org.entity.vo.RespAppMatchVO;
import com.ts.api.module.channel.entity.po.ChannelMarketPO;
import com.ts.api.module.channel.entity.vo.RespChannelMarketVO;
import com.ts.api.module.channel.service.ChannelMarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *  贷超接口
 *
 *  @author Pan
 */
@RestController
@RequestMapping("/app/market")
public class AppMarketController {

    @Autowired
    private ChannelMarketService channelMarketService;

    /**
     *  贷超推荐接口
     *
     *  @param  requestVO
     *  @return ResultVO
     */
    @GetMapping("/list")
    public ResultVO<Object> list(@RequestParamVo RequestVO requestVO) {
        List<ChannelMarketPO> list = channelMarketService.list(true);
        List<RespChannelMarketVO> listVO = CopyUtils.copyList(list, RespChannelMarketVO.class);
        return ResultVO.suc(listVO);
    }

    /**
     *  返回匹配贷超逻辑
     *
     *  @return ResultVO
     */
    @GetMapping("/match")
    public ResultVO<Object> match() {
        //  默认返回第一条推荐
        List<ChannelMarketPO> list = channelMarketService.list(true);
        if (ValidParam.isEmpty(list)) {
            return ResultVO.suc();
        }

        ChannelMarketPO marketPO = IteratorUtils.getFirst(list);
        RespAppMatchVO copy = CopyUtils.copy(marketPO, RespAppMatchVO.class);
        return ResultVO.suc(copy);
    }
}
